/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.business;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.modules.ivm.dao.business.ConcessionDao;
import com.neusoft.lohas.modules.ivm.entity.business.Concession;

/**
 * 商圈商店Service
 * @author Jackie.Liu
 * @version 2015-01-29
 */
@Component
@Transactional(readOnly = true)
public class ConcessionService extends BaseService {

	@Autowired
	private ConcessionDao concessionDao;
	
	public Concession get(String id) {
		return concessionDao.get(id);
	}
	
	public Page<Concession> find(Page<Concession> page, Concession concession) {
		DetachedCriteria dc = concessionDao.createDetachedCriteria();
		dc.add(Restrictions.eq(Concession.FIELD_DEL_FLAG, Concession.DEL_FLAG_NORMAL));
		dc.add(Restrictions.eq("merchant.id", concession.getMerchant().getId()));
		dc.addOrder(Order.asc("createDate"));
		return concessionDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(Concession concession) {
		concessionDao.clear();
		concessionDao.save(concession);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		concessionDao.deleteById(id);
	}

}
